package wg

import (
	"sync"
)

var mt sync.Mutex

func addByAtomic(number *int) {
	defer wg.Done()
	mt.Lock()
	*number += 1
	mt.Unlock()
}

var wg = sync.WaitGroup{}

func waitAll(times int) int {
	num := 0
	wg.Add(times)
	for i := 0; i < times; i++ {
		go addByAtomic(&num)
	}

	wg.Wait()

	return num
}
